package Sequence;

import java.util.ArrayList;
import java.util.List;

public class Test0047 {
}

class Solution0047_1 {
    List<List<Integer>> ans = new ArrayList<>();
    public List<List<Integer>> permuteUnique(int[] nums) {
        backtrack(new ArrayList<>(),nums,0);
        return ans;
    }

    public void backtrack(ArrayList<Integer> list, int[] nums,int record) {
        if (record == (1<<nums.length)-1) {
            ans.add(new ArrayList<>(list));
            return;
        }
        int record1 = 0;
        for (int i = 0; i < nums.length; i++) {
            int num = nums[i];
            if ((record1&(1<<(num+10)))==0&&(record&(1<<i))==0){
                list.add(num);
                record1 |= (1<<(num+10));
                backtrack(list,nums,record|(1<<i));
                list.remove(list.size()-1);
            }
        }

    }
}